package com.hyt.it.ogt.controller.pj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.core.util.FastJsonUtil;
import com.hyt.exception.annotation.ThrowsAdvice;
import com.hyt.it.ogt.common.config.ApiVersionConstant;
import com.hyt.it.ogt.data.enums.SubjectMarkTypeEnums;
import com.hyt.it.ogt.pj.common.ResponseCode;
import com.hyt.it.ogt.pj.model.param.*;
import com.hyt.it.ogt.pj.model.vo.*;
import com.hyt.it.ogt.pj.service.IProjectDfyhService;
import com.hyt.it.ogt.pj.service.IStudentService;
import com.hyt.loginfo.annotation.OgtPreAuthorize;
import com.hyt.loginfo.controller.BaseLoginController;
import com.hyt.model.PageParam;
import com.hyt.swagger.ApiVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评卷项目表 前端控制器东方雨虹
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
@ApiSort(value = 26)
@Api(tags = "26.评卷项目东方雨虹接口", value = "评卷项目东方雨虹接口")
@RestController
@RequestMapping("/dfyh/project")
@Slf4j
public class ProjectDfyhController extends BaseLoginController {

    @Autowired
    private IProjectDfyhService projectDfyhService;

    @Autowired
    private IStudentService studentService;

    @ApiOperationSort(value = 1)
    @ApiOperation(value = "26.1.1 查询评卷项目分页数据", notes = "20000:成功;")
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @ThrowsAdvice(code = 51000404, print = "查询评卷项目分页数据异常")
    @OgtPreAuthorize(values = {"gl_pj_page"})
    @PostMapping("page")
    public ApiResponse<Page<ProjectNewVo>> page(PageParam<ProjectNewVo> pageParam, ProjectPageParam projectPageParam) {
        log.debug("# 查询评卷项目分页数据参数 ： {}", FastJsonUtil.getBeanToJson(projectPageParam));
        String officeId = getOfficeId();
        return ApiResponse.<Page<ProjectNewVo>>builder()
                .code(ResponseCode.SUCCESS)
                .data(projectDfyhService.page(pageParam, projectPageParam.getProjectName(), projectPageParam.getMarkStatus(), officeId, projectPageParam.getClassfication(), null, projectPageParam.getProjectDataType()))
                .build();
    }

    @ApiOperationSort(value = 2)
    @ApiOperation(value = "26.1.2 查询单个评卷项目概览数据", notes = "20000:成功;")
    @GetMapping("overview/{id}")
    public ApiResponse<ProjectOverviewVo> getOverViewData(@PathVariable("id") String id) {
        log.debug("# 查询概览数据参数 ： {} ", id);
        try {
            return ApiResponse.<ProjectOverviewVo>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getOverViewData(id))
                    .build();
        } catch (Exception e) {
            log.error("# 查询单个评卷项目概览数据异常:", e);
            return ApiResponse.<ProjectOverviewVo>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 3)
    @ApiOperation(value = "26.1.3 查询单个评卷项目评卷任务分页数据", notes = "20000:成功;")
    @ThrowsAdvice(code = 51000404, print = "查询单个评卷项目评卷任务分页数据异常")
    @PostMapping("getProjectTaskPage")
    public ApiResponse<IPage<TaskPageItemVo>> getProjectTaskPage(PageParam<TaskPageItemVo> pageParam, TaskPageParam taskPageParam) {
        log.debug("# 查询单个评卷项目评卷任务分页数据 ： {} ", FastJsonUtil.getBeanToJson(taskPageParam));
        return ApiResponse.<IPage<TaskPageItemVo>>builder()
                .code(ResponseCode.SUCCESS)
                .data(studentService.taskStudentPage(pageParam, taskPageParam))
                .build();
    }

    @ApiOperationSort(value = 4)
    @ApiOperation(value = "26.1.4 评卷进度按模式分页数据", notes = "20000:成功;")
    @PostMapping("getMarkProgressPage")
    public ApiResponse<Page<MarkProgress1Vo>> getMarkProgressPage(PageParam<MarkProgress1Vo> pageParam, MarkProgerssParam markProgerssParam) {
        log.debug("# 查询评卷进度按模式分页数据 ： {} {} {}", markProgerssParam.getProjectId(), markProgerssParam.getSubjectId());
        try {
            return ApiResponse.<Page<MarkProgress1Vo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.markProgressPage(pageParam, markProgerssParam.getProjectId(), markProgerssParam.getSubjectId(), markProgerssParam.getPlaceId(), markProgerssParam.getRoomId()))
                    .build();
        } catch (Exception e) {
            log.error("# 查询评卷进度按模式分页数据异常:", e);
            return ApiResponse.<Page<MarkProgress1Vo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 5)
    @ApiOperation(value = "26.1.5 评卷进度按专家分页数据", notes = "20000:成功;")
    @PostMapping("getMarkProgress2Page")
    public ApiResponse<Page<MarkProgress2Vo>> getMarkProgress2Page(PageParam<MarkProgress2Vo> pageParam, MarkProgerssParam2 markProgerssParam) {
        log.debug("# 查询评卷进度按专家数据 ： {} {} {}", markProgerssParam.getProjectId(), markProgerssParam.getSubjectId(), markProgerssParam.getExpertName());
        try {
            return ApiResponse.<Page<MarkProgress2Vo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.markProgress2Page(pageParam, markProgerssParam.getProjectId(), markProgerssParam.getSubjectId(), markProgerssParam.getExpertName()))
                    .build();
        } catch (Exception e) {
            log.error("# 查询评卷进度按专家分页数据异常:", e);
            return ApiResponse.<Page<MarkProgress2Vo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 6)
    @ApiOperation(value = "26.1.6 根据项目查询批次", notes = "20000:成功;")
    @PostMapping("getBatchByProject/{projectId}")
    public ApiResponse<List<OptionItemVo>> getBatchByProject(@PathVariable("projectId") String projectId) {
        log.debug("# 根据项目查询批次 ： {} ", projectId);
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getBatchByProject(projectId))
                    .build();
        } catch (Exception e) {
            log.error("# 根据项目查询批次异常:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 7)
    @ApiOperation(value = "26.1.7 根据项目查询考点", notes = "20000:成功;")
    @PostMapping("getPlaceByProject/{projectId}")
    public ApiResponse<List<OptionItemVo>> getPlaceByProject(@PathVariable("projectId") String projectId) {
        log.debug("# 根据项目查询考点 ： {} ", projectId);
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getPlaceByProject(projectId))
                    .build();
        } catch (Exception e) {
            log.error("# 根据项目查询考点异常:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 8)
    @ApiOperation(value = "26.1.8 根据项目查询考场", notes = "20000:成功;")
    @PostMapping("getRoomByProject/{projectId}/{placeId}")
    public ApiResponse<List<OptionItemVo>> getRoomByProject(@PathVariable("projectId") String projectId, @PathVariable("placeId") String placeId) {
        log.debug("# 根据项目查询考场 ： {} ", projectId);
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getRoomByProject(projectId, placeId))
                    .build();
        } catch (Exception e) {
            log.error("# 根据项目查询考场异常:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 9)
    @ApiOperation(value = "26.1.9 根据项目查询科目", notes = "20000:成功;")
    @PostMapping("getSubjectByProject/{projectId}")
    public ApiResponse<List<OptionItemVo>> getSubjectByProject(@PathVariable("projectId") String projectId) {
        log.debug("# 根据项目查询科目 ： {} ", projectId);
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getSubjectByProject(projectId, SubjectMarkTypeEnums.NEED))
                    .build();
        } catch (Exception e) {
            log.error("# 根据项目查询科目异常:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }


    @ApiOperationSort(value = 10)
    @ApiOperation(value = "26.1.10 查询专家下面科目", notes = "20000:成功;")
    @PostMapping("/getExpertSubject")
    public ApiResponse<List<OptionItemVo>> getExpertSubject(@RequestBody ExamExpertSettingParam param) {
        String userId = getUserId();
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getExpertSubject(param, userId))
                    .build();
        } catch (Exception e) {
            log.error("# 查询专家下面科目异常:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 10)
    @ApiOperation(value = "26.1.10 查询专家下面考点", notes = "20000:成功;")
    @PostMapping("getExpertPlace/{projectId}")
    public ApiResponse<List<OptionItemVo>> getExpertPlace(@PathVariable("projectId") String projectId) {
        log.debug("# 查询专家下面考点 ： {} ", projectId);
        String officeId = getUserId();
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getExpertPlace(projectId, officeId))
                    .build();
        } catch (Exception e) {
            log.error("# 查询专家下面考点异常:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }

    @ApiOperationSort(value = 11)
    @ApiOperation(value = "26.1.11 查询考点下面考场", notes = "20000:成功;")
    @PostMapping("getExpertRoom/{projectId}/{palceId}")
    public ApiResponse<List<OptionItemVo>> getExpertPlace(@PathVariable("projectId") String projectId, @PathVariable("palceId") String palceId) {
        log.debug("# 查询考点下面考场 ： {} ", projectId);
        try {
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.SUCCESS)
                    .data(projectDfyhService.getExpertRoom(projectId, palceId))
                    .build();
        } catch (Exception e) {
            log.error("# 查询考点下面考场:", e);
            return ApiResponse.<List<OptionItemVo>>builder()
                    .code(ResponseCode.QUERY_PROJECT_PAGE_FAIL)
                    .build();
        }
    }
}
